<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 审批流
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
                <sec:authorize access="hasRole('ROLE_ENTERPRISE_AUDIT_FLOW_EDIT')">
                    <a href="javascript:;" onclick="vLayuiUtil.openLayerWindow('wAuditFlow', '<c:url
                            value="/web/admin/auditFlow/editPage.action"/>','编辑')" class="btn btn-default btnTool"
                       title="新增故障分类"><i class="fa fa-plus"></i> 新增</a>
                </sec:authorize>

            </div>
        </div>
        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/admin/auditFlow/listJson.action"/>" method="post"
                  class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <div class="form-group">
                    <label class="control-label">名称：</label>
                    <div class="control-inline">
                        <input type="text" id="searchCode" name="searchCode" value="" maxlength="64"
                               class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">审批类型：</label>
                    <div class="control-inline" style="width: 120px">
                        <select id="auditType" name="auditType" class="form-control">
                            <option value="">全部</option>
                            <c:forEach items="${auditTypeArray}" var="type">
                                <option value="${type.code}">${type.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">所属应用：</label>
                    <div class="control-inline">
                        <input type="text" id="applicationName" name="applicationName" value="" maxlength="64"
                               class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>
            <div style="overflow-x:auto">
                <table id="auditFlowGrid"></table>
            </div>
            <div id="auditFlowGridPage"></div>
        </div>
    </div>
</div>
<script>
    $('#auditFlowGrid').dataGrid({
        searchForm: $("#searchForm"),
        shrinkToFit: false,
        autoScroll: true,
        columnModel: [
            {header: '名称', name: 'flowName', index: 'flowName', width: 300, align: "center"},
            {header: '审批类型', name: 'auditTypeEnum', index: 'auditTypeEnum', width: 300, align: "center"},
            {header: '所属应用', name: 'applicationName', index: 'applicationName', width: 200, align: "center"},
            {header: '是否默认审批流', name: 'defaultV', index: 'defaultV', width: 200, align: "center"},
            {header: '创建人', name: 'createUser', index: 'createUser', width: 200, align: "center"},
            {header: '所属企业', name: 'enterpriseName', index: 'enterpriseName', width: 200, align: "center"},
            <sec:authorize access="hasRole('ROLE_ENTERPRISE_AUDIT_FLOW_EDIT')">
            {
                header: '操作',
                name: 'actions',
                width: 250,
                sortable: false,
                title: false,
                formatter: function (val, obj, row, act) {
                    var actions = [];
                    var editUrl = '<c:url value="/web/admin/auditFlow/editPage.action?id="/>' + row.id;
                    var nodeUrl = '<c:url value="/web/admin/auditFlow/editNodePage.action?id="/>' + row.id;

                    actions.push('<a href="javascript:;" class="btn btn-default btn-xs btnList" onclick="vLayuiUtil.openLayerWindow(\'wAuditFlow\', \'' + editUrl + '\',\'编辑\')"><i class="fa fa-pencil"></i>编辑</a>&nbsp;&nbsp;&nbsp;');
                    actions.push('<a href="javascript:;" class="btn btn-default btn-xs btnList" onclick=" submitRemove(\'' + row.id + '\', \'0\')"><i class="fa fa-trash-o"></i>删除</a>&nbsp;&nbsp;&nbsp;');
                    actions.push('<a href="javascript:;" class="btn btn-default btn-xs btnList" onclick="vLayuiUtil.openLayerIframMaxWindow(\'wAuditFlow\', \'' + nodeUrl + '\',\'编辑节点\')"><i class="fa fa-pencil"></i>编辑节点</a>&nbsp;&nbsp;&nbsp;');

                    return actions.join('');

                }
            }
            </sec:authorize>
        ],
        // 加载成功后执行事件
        ajaxSuccess: function (data) {

        }
    });

    function submitRemove(id) {
        js.confirm('你确认要删除这条数据吗？', function () {
            $.ajax({
                type: 'post',
                url: "<c:url value="/web/admin/auditFlow/delete.action" />",
                data: {"id": id},
                dataType: 'json',
                async: false,
                success: function (data) {
                    js.showMessage(data.msg);
                    $('#auditFlowGrid').dataGrid('refresh');
                },
                error: function () {
                    js.showMessage("出错了，请联系管理员");
                }
            });
        })
    }
</script>
<script src="<c:url value="/resources/wdScrollTab/js/TabPanel.js" />"></script>

